﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zhjt.Comm.Lib.Tools.ConfigTools
{
    public static class SystemConfigTools
    {
        /// <summary>
        /// 获取配置文件AppSettings节点中指定Key的Value
        /// </summary>
        /// <typeparam name="T">要返回的类型</typeparam>
        /// <param name="key"></param>
        /// <returns></returns>
        public static T GetAppSettings<T>(string key)
        {
            if (string.IsNullOrEmpty(key)) return default(T);
            string value = System.Configuration.ConfigurationManager.AppSettings[key];
            if(string.IsNullOrEmpty(value)) return default(T);
            TypeConverter typeConverter = TypeDescriptor.GetConverter(typeof(T));
            object propValue = typeConverter.ConvertFromString(value);
            return (T)propValue;
        }
    }
}
